<include file="Public/header"/>
<body class="body-bg">
<div class="park-header">
    <div class="park-header__left park-back">
        <i class="iconfont icon-fanhui"></i>
    </div>
    <div class="park-header__title"><if condition="$act eq 'add'">添加<else />编辑</if>地址</div>
</div>
<div class="container">
    <form action="/Home/User/add_address/" method="post" onsubmit="return false;">
        <div class="park-row-list">
            <div class="park-row-item">
                <div class="park-row-item__left">
                    <span>收货人:</span>
                </div>
                <div class="park-row-item__right">
                    <input type="text" id="name" name="name" value="{$info.name}" placeholder="请输入联系人">
                </div>
            </div>
            <div class="park-row-item">
                <div class="park-row-item__left">
                    <span>联系电话:</span>
                </div>
                <div class="park-row-item__right">
                    <input type="text" id="mobile" name="mobile" value="{$info.mobile}" placeholder="请输入电话号码">
                </div>
            </div>
            <div class="park-row-item">
                <div class="park-row-item__left">
                    <span>所有地区:</span>
                </div>
                <div class="park-row-item__right">
                    <input id="address-name" name="area" readonly type="text" value="{$info.address_area}"><i class="iconfont icon-gengduo"></i>
                </div>
            </div>
            <div class="park-row-item">
                <div class="park-row-item__left">
                    <span>详细地址:</span>
                </div>
                <div class="park-row-item__right">
                    <input type="text" name="address" value="{$info.address}" id="address" placeholder="请输入街道、楼牌号等">
                </div>
            </div>
            <input type="hidden" name="act" value="{$act}">
            <input type="hidden" name="id" value="{$info.id}">
            <input type="hidden" name="area_id" id="address-id" value="{$info.province},{$info.city},{$info.area}">
        </div>
        <button type="submit" class="park-btn park-btn-bottom park-btn-default mt-footer__btn" onclick="check_form();">保存</button>
    </form>
<script src="__ROOT__/Public/Home/layer/layer.js"></script>

<link rel="stylesheet" href="__ROOT__/Public/Home/javascripts/area/dialog.min.css">
<link rel="stylesheet" href="__ROOT__/Public/Home/javascripts/area/mobile-select-area.min.css">
<script src="__ROOT__/Public/Home/javascripts/LAreaData1.js"></script>
<script src="__ROOT__/Public/Home/javascripts/area/dialog.min.js"></script>
<script src="__ROOT__/Public/Home/javascripts/area/mobile-select-area.min.js"></script>
<script>
    $(function () {
        var selectArea = new MobileSelectArea();
        selectArea.init({trigger:$('#address-name'), text: ['', '' , ''], value:$('#address-id').val(), data: LAreaData, position:'bottom'});
    });
    function check_form(){
        var error = false;
        var address = $('#address').val();
        if(!address){
            error = '请输入街道、楼牌号等';
        }
        var area = $('#address-name').val();
        if(!area){
            error = '请选择地区';
        }
        var mobile = $('#mobile').val();
        if(!mobile){
            error = '请输入电话号码';
        }
        var name = $('#name').val();
        if(!name){
            error = '请输入联系人';
        }
        if(error){
            layer.open({
                content:error
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
            });
            return false;
        }
        var act = '{$act}';
        var id = '{$info.id}';
        var area_id = $('#address-name').attr('data-value');
        $.post('/Home/User/add_address/',{name:name,mobile:mobile,act:act,id:id,address:address,area:area,area_id:area_id},function(data){
            if(data.code==200){
                layer.open({
                    content:data.msg
                    ,btn: ['确定']
                    ,yes: function(index){
                       window.location = '/Home/User/address/';
                    }
                });
            }else{
                layer.open({
                    content:data.msg
                    ,skin: 'msg'
                    ,time: 2 //2秒后自动关闭
                });
            }
        },'json');
        return false;
    }
</script>
</body>
</html>